<template>
  <div class="menus-manage">
    <!-- 面包屑 -->
    <div class="bread-crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>入离调转</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="main-middle">
      <el-card class="box-card">
        <!-- 查询条件 -->
        <el-row class="table-selbox" v-if="btnSel">
          <!-- 查询条件表单 -->
          <el-form :inline="true" :model="formInline">
            <el-form-item label="签约主体">
              <el-select
                  v-model="formInline.signCompany"
                  auto-complete="off"
                  placeholder="请选择"
                  filterable
                  style="width:100%;"
                >
                <el-option-group label="默认值">
                  <el-option label="无" value="0"></el-option>
                </el-option-group>
                  <el-option-group
                    v-for="group in signCompanyList"
                    :key="group.label"
                    :label="group.label">
                    <el-option
                      v-for="item in group.options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-option-group>
                </el-select>
            </el-form-item>
            <el-form-item label="所属部门">
              <el-cascader
                  style="width: 100%;"
                  v-model="formInline.deptId"
                  :options="depList"
                  :props="{ expandTrigger: 'hover', checkStrictly: true }"
                  @change="handleChange" filterable></el-cascader>
            </el-form-item>
            <!-- 员工姓名 -->
            <el-form-item label="姓名工号">
              <el-autocomplete
                v-model="formInline.userId"
                :fetch-suggestions="querySearchAsync"
                placeholder="请输入姓名"
                @select="handleSelect"
                clearable
              >
                <template slot-scope="{ item }">
                  <div class="selName">
                    <span>{{ item.userName }}</span>
                    <span>[{{ item.userId }}]</span>
                  </div>
                </template>
              </el-autocomplete>
            </el-form-item>
            <el-form-item label="在职状态">
              <el-select v-model="formInline.status">
                <el-option label="无" value=""></el-option>
                <el-option label="在职" value="0"></el-option>
                <el-option label="离职" value="1"></el-option>
                <el-option label="待入职" value="2"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="员工类别">
              <el-select v-model="formInline.type">
                <el-option label="无" value="0"></el-option>
                <el-option label="正式员工" value="1"></el-option>
                <el-option label="自由顾问" value="2"></el-option>
                <el-option label="实习生" value="3"></el-option>
                <el-option label="外协员工" value="4"></el-option>
                <el-option label="百德劳务" value="5"></el-option>
                <el-option label="赛特斯主体员工" value="6"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="内部级别">
              <el-select v-model="formInline.insideLevel" clearable maxlength="15">
                <el-option label="无" value=""></el-option>
                <el-option label="初级" value="1"></el-option>
                <el-option label="中级" value="2"></el-option>
                <el-option label="高级" value="3"></el-option>
                <el-option label="资深" value="4"></el-option>
              </el-select>
            </el-form-item>
            <!-- <el-form-item label="客户级别单价(含税)">
              <el-input v-model.trim="formInline.userLevel" clearable maxlength="15"></el-input>
            </el-form-item> -->
            <!-- 搜索 -->
            <el-form-item>
              <el-button icon="el-icon-search" @click="selHandle">搜索</el-button>
            </el-form-item>
            <el-form-item>
              <el-button icon="el-icon-search" @click="reseatHandle">重置</el-button>
            </el-form-item>
          </el-form>
        </el-row>
        <!-- 基本操作按钮 是否授权显示-->
        <el-row class="table-btns" v-if="[btnAdd,btnDel,btnUpload,btnDown].indexOf(true) > -1">
          <!-- 添加 -->
          <el-button
            v-if="btnAdd"
            type="success"
            size="medium"
            icon="el-icon-document-add"
            @click="addHandle"
          >添加</el-button>
          <el-button type="success" size="medium" style="float:right;" v-if="btnDown" @click="getHistory">
            <i class="fa fa-cloud-download" aria-hidden="true"></i> 变更历史
          </el-button>
        </el-row>
        <!-- 数据列表 -->
        <el-table
          :data="usersData"
          border
          style="width: 100%"
          height="520"
          ref="usersData"
        >
          <!-- 全选 -->
          <!-- <el-table-column type="selection" width="40" fixed></el-table-column> -->
          <!-- 序号 -->
          <el-table-column label="序号" align="center" type="index" width="50"></el-table-column>
          <!-- 员工姓名 -->
          <el-table-column prop="userName" label="员工姓名" width="120"></el-table-column>
          <!-- 员工工号 -->
          <el-table-column prop="userId" label="员工工号" width="120"></el-table-column>
          <!-- 签约主体 -->
          <el-table-column label="签约主体" width="300">
            <!-- 过滤判断 1 上海浩方信息技术有限公司南京分公司  2 上海浩方信息技术有限公司北京分公司 2 上海浩方信息技术有限公司上海分公司 -->
            <template slot-scope="scope">
              <span v-if="scope.row.signCompany === 1">上海浩方信息技术有限公司南京分公司</span>
              <span v-else-if="scope.row.signCompany === 2">上海浩方信息技术有限公司北京分公司</span>
              <span v-else-if="scope.row.signCompany === 3">上海浩方信息技术有限公司</span>
              <span v-else-if="scope.row.signCompany === 4">南京璨错网络科技有限公司</span>
              <span v-else-if="scope.row.signCompany === 5">南京凌睿吉信息技术有限公司</span>
              <span v-else-if="scope.row.signCompany === 6">重庆赛辰科技有限公司</span>
              <span v-else-if="scope.row.signCompany === 7">佰德人力资源集团有限公司</span>
              <span v-else-if="scope.row.signCompany === 8">北京赛特斯信息科技股份有限公司</span>
              <span v-else-if="scope.row.signCompany === 9">赛特斯信息科技股份有限公司</span>
              <span v-else-if="scope.row.signCompany === 10">广东赛特斯信息科技有限公司</span>
              <span v-else-if="scope.row.signCompany === 11">上海赛特斯信息科技股份有限公司</span>
            </template>
          </el-table-column>
          <!-- 一级部门 -->
          <el-table-column sortable :show-overflow-tooltip="true" label="一级部门" width="150">
            <template slot-scope="scope">{{ scope.row.dn1 | fileLv([1, scope.row.level, scope.row.deptName, scope.row.dn2, scope.row.dn1]) }}</template>
          </el-table-column>
          <!-- 二级部门 -->
          <el-table-column sortable :show-overflow-tooltip="true" label="二级部门" width="150">
            <template slot-scope="scope">{{ scope.row.dn2 | fileLv([2, scope.row.level, scope.row.deptName, scope.row.dn2, scope.row.dn1]) }}</template>
          </el-table-column>
          <!-- 三级部门 -->
          <el-table-column sortable :show-overflow-tooltip="true" label="三级部门" width="150">
            <template slot-scope="scope">{{ scope.row.deptName | fileLv([3, scope.row.level, scope.row.deptName, scope.row.dn2, scope.row.dn1]) }}</template>
          </el-table-column>
          <!-- 岗位名称 -->
          <el-table-column :show-overflow-tooltip="true" prop="position" label="岗位名称" width="150"></el-table-column>
          <!-- 员工类别 -->
          <el-table-column label="员工类别" width="150">
            <!-- 过滤判断 1 正式员工  2 自由顾问 2 实习生 -->
            <template slot-scope="scope">
              <span v-if="scope.row.type === 1">正式员工</span>
              <span v-else-if="scope.row.type === 2">自由顾问</span>
              <span v-else-if="scope.row.type === 3">实习生</span>
              <span v-else-if="scope.row.type === 4">外协员工</span>
              <span v-else-if="scope.row.type === 5">赛特斯主体员工</span>
              <span v-else-if="scope.row.type === 6">百德劳务</span>
            </template>
          </el-table-column>
          <!-- 内部级别 -->
          <el-table-column prop="insideLevel" label="内部级别" width="120">
            <!-- 过滤判断 1 初级  2 中级 3 高级 4 资深 -->
            <template slot-scope="scope">
              <span v-if="scope.row.insideLevel === 1">初级</span>
              <span v-else-if="scope.row.insideLevel === 2">中级</span>
              <span v-else-if="scope.row.insideLevel === 3">高级</span>
              <span v-else-if="scope.row.insideLevel === 4">资深</span>
              <span v-else >无</span>
            </template>
          </el-table-column>
          <!-- 在职状态 -->
          <el-table-column label="员工状态" width="150">
            <!-- 过滤判断 0 在职  1 离职 2 待入职 -->
            <template slot-scope="scope">
              <span v-if="scope.row.status === 0">在职</span>
              <span v-else-if="scope.row.status === 1">离职</span>
              <span v-else>待入职</span>
            </template>
          </el-table-column>
          <!-- 归属地 -->
          <el-table-column prop="location" label="归属地" width="120"></el-table-column>
          <!-- 入职时间 -->
          <el-table-column label="入职时间" width="150">
            <template slot-scope="scope">{{ scope.row.joinTime | filterTime }}</template>
          </el-table-column>
          <!-- 参与工作时间 -->
          <el-table-column sortable :show-overflow-tooltip="true" prop="workTime" label="参与工作时间" width="150"></el-table-column>
          <!-- 财务口径 -->
          <el-table-column sortable :show-overflow-tooltip="true" prop="caliber" label="财务口径" width="150">
             <!-- 过滤判断 1 初级  2 中级 3 高级 4 资深 -->
            <template slot-scope="scope">
              <span v-if="scope.row.caliber === '0'">财务部</span>
              <span v-else-if="scope.row.caliber === '1'">商务部</span>
              <span v-else-if="scope.row.caliber === '2'">项目部</span>
              <span v-else-if="scope.row.caliber === '3'">项目管理办公室</span>
              <span v-else-if="scope.row.caliber === '4'">销售部</span>
              <span v-else-if="scope.row.caliber === '5'">研发部</span>
              <span v-if="scope.row.caliber === '6'">综合事务部</span>
            </template>
          </el-table-column>
          <!-- 客户级别单价(含税) -->
          <el-table-column prop="userLevel" label="客户级别" width="120"></el-table-column>
          <!-- 身份证号码 -->
          <el-table-column sortable :show-overflow-tooltip="true" label="身份证号码" width="150">
            <template slot-scope="scope">{{ scope.row.idCard | filterIdCard }}</template>
          </el-table-column>
          <!-- 社保公积金参险地 -->
          <el-table-column sortable :show-overflow-tooltip="true" prop="insured" label="社保公积金参险地" width="180"></el-table-column>
          <!-- 社保基数 -->
          <el-table-column sortable :show-overflow-tooltip="true" prop="insuredBase" label="社保基数" width="150"></el-table-column>
          <!-- 公积金基数 -->
          <el-table-column sortable :show-overflow-tooltip="true" prop="accumBase" label="公积金基数" width="150"></el-table-column>
          <!-- 社保缴纳公司 -->
          <el-table-column sortable :show-overflow-tooltip="true" prop="insuredGs" label="社保缴纳公司" width="150"></el-table-column>
          <!-- 员工性别 -->
          <el-table-column label="员工性别" width="120" prop="sex">
            <!-- 过滤判断  男：1 女：0 -->
            <template slot-scope="scope">{{ scope.row.sex === 0 ? '女' : '男'}}</template>
          </el-table-column>
          <!-- 出生日期 -->
          <el-table-column sortable :show-overflow-tooltip="true" prop="birthday" label="出生日期" width="150"></el-table-column>
          <!-- 邮箱 -->
          <el-table-column sortable :show-overflow-tooltip="true" prop="email" label="邮箱" width="150"></el-table-column>
          <!-- 联系方式 -->
          <el-table-column sortable :show-overflow-tooltip="true" prop="tell" label="联系方式" width="150"></el-table-column>
          <!-- 离职时间 -->
          <el-table-column label="离职时间" width="150">
            <template slot-scope="scope">{{ scope.row.quitTime | filterTime }}</template>
          </el-table-column>
          <!-- 备注说明 -->
          <!-- <el-table-column prop="note" label="备注说明" :show-overflow-tooltip="true"></el-table-column> -->
          <!-- 操作列 -->
          <el-table-column
            label="管理"
            fixed="right"
            align="center"
            width="100"
            v-if="[btnDel,btnEdit].indexOf(true) > -1"
          >
            <template slot-scope="scope">
              <el-dropdown>
                <el-button type="primary" size="mini">
                  操作<i class="el-icon-arrow-down el-icon--right"></i>
                </el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item><el-button size="mini" @click="editHandle(scope.row, 1)" v-if="btnEdit">变更</el-button></el-dropdown-item>
                  <el-dropdown-item><el-button type="success" size="mini" @click="editHandle(scope.row, 2)" v-if="btnEdit && scope.row.status === 0">调岗</el-button></el-dropdown-item>
                  <el-dropdown-item><el-button type="warning" size="mini" @click="editHandle(scope.row, 3)" v-if="btnEdit && scope.row.status === 0">离职</el-button></el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
              <!-- 删除 -->
              <!-- <el-button type="danger" size="mini" @click="handleDelete(scope.row)" v-if="btnDel">删除</el-button> -->
              <!-- 修改 -->
              <!-- <el-button size="mini" @click="editHandle(scope.row, 1)" v-if="btnEdit">变更</el-button> -->
               <!-- 调岗 -->
              <!-- <el-button type="success" size="mini" @click="editHandle(scope.row, 2)" v-if="btnEdit && scope.row.status === 0">调岗</el-button> -->
               <!-- 离职 -->
              <!-- <el-button type="warning" size="mini" @click="editHandle(scope.row, 3)" v-if="btnEdit && scope.row.status === 0">离职</el-button> -->
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <div class="table-pageblock">
          <!-- current-page 当前页数  page-size 每页显示数 total 总页数-->
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[20,50,80,100]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          ></el-pagination>
        </div>
      </el-card>

      <!-- 弹窗 新增or修改 -->
      <el-dialog
        :title="textMap[dialogStatus]"
        :visible.sync="dialogFormVisible"
        :close-on-click-modal="false"
      >
      <!-- 添加、修改表单 -->
        <el-form ref="editForm" :model="editForm" label-width="80px" :rules="editFormRules">
          <!-- 签约主体、 员工类型-->
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="签约主体" prop="signCompany">
                <el-select
                  v-model="editForm.signCompany"
                  auto-complete="off"
                  placeholder="请选择"
                  filterable
                  style="width:100%;"
                >
                <!-- <el-option-group label="默认值">
                  <el-option label="无" value="0"></el-option>
                </el-option-group> -->
                  <el-option-group
                    v-for="group in signCompanyList"
                    :key="group.label"
                    :label="group.label">
                    <el-option
                      v-for="item in group.options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-option-group>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="员工类型" prop="type">
                <el-select style="width:100%;" v-model="editForm.type" filterable @change="changeType">
                  <el-option label="正式员工" value="1">正式员工</el-option>
                  <el-option label="自由顾问" value="2">自由顾问</el-option>
                  <el-option label="实习生" value="3">实习生</el-option>
                  <el-option label="外协员工" value="4">外协员工</el-option>
                  <el-option label="赛特斯主体员工" value="5">赛特斯主体员工</el-option>
                  <el-option label="百德劳务" value="6">百德劳务</el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 员工姓名、 员工工号-->
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="员工姓名" prop="userName">
                <el-input v-model="editForm.userName" auto-complete="off"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="员工工号" prop="userId" v-if="isShowUserCode">
                <el-input v-model="editForm.userId" auto-complete="off" :disabled="isedit" ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 入职时间、 部门名称-->
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="入职时间" prop="joinTime">
                <el-date-picker
                  v-model="editForm.joinTime"
                  type="date"
                  placeholder="选择日期"
                  style="width:100%;"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="部门名称" prop="compDept">
                <el-cascader
                 :disabled="isedit"
                  ref="cascaderDept"
                  style="width: 100%;"
                  v-model="editForm.compDept"
                  :options="option"
                  :props="{ expandTrigger: 'hover', checkStrictly: true }"
                  @change="handleChange" filterable></el-cascader>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 财务口径、 岗位名称-->
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="财务口径" prop="caliber">
                <el-select style="width:100%;" v-model="editForm.caliber" filterable>
                  <el-option label="财务部" value="0">财务部</el-option>
                  <el-option label="商务部" value="1">商务部</el-option>
                  <el-option label="项目部" value="2">项目部</el-option>
                  <el-option label="项目管理办公室" value="3">项目管理办公室</el-option>
                  <el-option label="销售部" value="4">销售部</el-option>
                  <el-option label="研发部" value="5">研发部</el-option>
                  <el-option label="综合事务部" value="6">综合事务部</el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="岗位名称">
                <el-select
                    v-model="editForm.position"
                    auto-complete="off"
                    placeholder="请选择"
                    filterable
                    style="width:100%;"
                  >
                  <el-option-group label="默认值">
                    <el-option label="无" value="0"></el-option>
                  </el-option-group>
                    <el-option-group
                      v-for="group in positionList"
                      :key="group.label"
                      :label="group.label">
                      <el-option
                        v-for="item in group.options"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-option-group>
                  </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 身份证号码、员工性别-->
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="身份证号码" prop="idCard" class="userlevel-box">
                <el-input v-model="editForm.idCard" auto-complete="off" maxlength="18"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="员工性别" prop="sex">
                <el-select style="width:100%;" v-model="editForm.sex">
                  <el-option label="男" value="1">男</el-option>
                  <el-option label="女" value="0">女</el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 出生日期、在职状态-->
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="出生日期" prop="birthday">
                <el-date-picker
                  v-model="editForm.birthday"
                  type="date"
                  placeholder="选择日期"
                  style="width:100%;"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="状态" prop="status">
                <el-select style="width:100%;" v-model="editForm.status" :disabled="isedit">
                  <el-option label="在职" value="0">在职</el-option>
                  <el-option label="离职" value="1">离职</el-option>
                  <el-option label="待入职" value="2">待入职</el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 归属地、参与工作时间-->
          <el-row :gutter="24">
             <el-col :span="12">
              <el-form-item label="归属地" prop="location">
                <el-cascader
                  ref="cascaderLoc"
                  style="width: 100%;"
                  v-model="editForm.location"
                  :options="areaOption"
                  :props="{ expandTrigger: 'hover', checkStrictly: true }"
                  @change="handleChange" filterable></el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="参与工作时间" prop="workTime" class="userlevel-box">
                <el-date-picker
                  v-model="editForm.workTime"
                  type="date"
                  placeholder="选择日期"
                  style="width:100%;"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 联系方式、客户级别-->
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="联系方式" prop="tell">
                <el-input v-model="editForm.tell" auto-complete="off" maxlength="11"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="客户级别单价(含税)" prop="userLevel" class="userlevel-box">
                <el-input v-model="editForm.userLevel" auto-complete="off" placeholder="月单价折算人天单价的规则/20.83"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 内部级别、社保公积金参险地-->
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="内部级别" prop="insideLevel">
                <el-select style="width:100%;" v-model="editForm.insideLevel" clearable maxlength="15" auto-complete="off" filterable>
                  <el-option label="无" value=""></el-option>
                  <el-option label="初级" value="1"></el-option>
                  <el-option label="中级" value="2"></el-option>
                  <el-option label="高级" value="3"></el-option>
                  <el-option label="资深" value="4"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="社保公积金参险地" prop="insured" class="userlevel-box">
                <el-cascader
                  ref="cascader"
                  style="width: 100%;"
                  v-model="editForm.insured"
                  :options="areaOption"
                  :props="{ expandTrigger: 'hover', checkStrictly: true }"
                  @change="handleChange" filterable></el-cascader>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 社保基数、公积金基数-->
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="社保基数" prop="insuredBase">
                <el-input v-model="editForm.insuredBase" auto-complete="off"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="公积金基数" prop="accumBase" class="userlevel-box">
                <el-input v-model="editForm.accumBase" auto-complete="off"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 社保缴纳公司、邮箱-->
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="社保缴纳公司" prop="insuredGs" class="userlevel-box">
                <el-input v-model="editForm.insuredGs" auto-complete="off"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="邮箱" prop="email">
                <el-input v-model="editForm.email" auto-complete="off"></el-input>
              </el-form-item>
            </el-col>
            <!-- <el-col :span="12">
              <el-form-item label="离职时间" prop="quitTime">
                <el-date-picker
                  v-model="editForm.quitTime"
                  type="date"
                  placeholder="选择日期"
                  style="width:100%;"
                  :disabled="isedit"
                ></el-date-picker>
              </el-form-item>
            </el-col> -->
          </el-row>
          <el-row>
            <el-col :span="12">
              <!-- 生效日期 -->
              <el-form-item label="生效日期" prop="day">
                <el-date-picker
                  v-model="editForm.day"
                  type="date"
                  placeholder="选择日期"
                  style="width:100%;"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 备注说明 -->
          <!-- <el-form-item label="备注说明" prop="note">
            <el-input
              type="textarea"
              placeholder="备注说明（20字以内）"
              maxlength="20"
              v-model="editForm.note"
            ></el-input>
          </el-form-item> -->
        </el-form>
        <div slot="footer" class="dialog-footer">
          <!-- 取消 关闭弹窗 -->
          <el-button @click.native="dialogFormVisible=false">取消</el-button>
          <!-- 添加 清空表单初始数据 -->
          <el-button
            v-if="dialogStatus=='create'"
            type="primary"
            @click="createData"
          >添加</el-button>
          <!-- 修改获取表单初始数据 -->
          <el-button v-else type="primary" @click="editData">修改</el-button>
        </div>
      </el-dialog>
      <!-- 离职/调岗 -->
      <el-dialog :title="changeText" :visible.sync="modalVisible">
         <el-form ref="changeForm" :model="changeForm" label-width="80px" :rules="changeFormRules">
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="员工工号" prop="userId">
                <el-input v-model="changeForm.userId" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="姓名" prop="userName">
                <el-input v-model="changeForm.userName" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12" v-if="isOut">
              <!-- 公司部门选择框子组件 -->
              <el-form-item label="公司部门">
                <el-cascader
                  style="width: 100%;"
                  v-model="changeForm.compDept"
                  :options="option"
                  :props="{ expandTrigger: 'hover', checkStrictly: true }"
                  @change="handleChangeDept(changeForm.compDept)"></el-cascader>
                </el-form-item>
              <!-- <org-tree
                v-model="changeForm.compDept"
                :compdepts="compdepts"
                :comps="compsList"
                :selcpms="selcpmsVal"
                @selcompdepts="getCompDept"
              ></org-tree> -->
            </el-col>
            <el-col :span="12">
              <!-- 生效日期 -->
              <el-form-item label="生效日期" prop="day">
                <el-date-picker
                  v-model="changeForm.day"
                  type="date"
                  placeholder="选择日期"
                  style="width:100%;"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 备注说明 -->
          <!-- <el-form-item label="备注说明" prop="note" v-if="!isOut">
            <el-input
              type="textarea"
              placeholder="备注说明（20字以内）"
              maxlength="20"
              v-model="changeForm.note"
            ></el-input>
          </el-form-item> -->
        </el-form>
        <div slot="footer" class="dialog-footer">
          <!-- 取消 关闭弹窗 -->
          <el-button @click.native="modalVisible=false">取消</el-button>
          <!-- 修改获取表单初始数据 -->
          <el-button type="primary" @click="changeUser">确认</el-button>
        </div>
      </el-dialog>
      <!-- 变更历史弹框 -->
      <el-dialog :title="exportTitle" :visible.sync="timeSliceVisible" width="600px">
        <div class="fileAsset">
          <el-form>
            <el-form-item label="时间范围" prop="logTime">
              <el-date-picker
                v-model="formInline.logTime"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
              </el-date-picker>
            </el-form-item>
          </el-form>
          <p style="width: 320px;line-height:20px;">备注说明：导出规则，根据导出设置的字段与时间范围导出该时间范围内的员工全量数据</p>
        </div>
        <div slot="footer" class="dialog-footer">
          <!-- 确认导出 关闭弹窗 -->
          <el-button type="primary" size="medium" @click="setUpAssetExcel">确认</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
// 引入地区数据
import { province, city } from '../../../static/js/vue-area.js';
// 引入时间格式化插件
import moment from 'moment';
// 引入公司部门选择徐建
import orgTree from '@/components/OrgTree/index.vue';
import { export2Excel, getName } from '../../public/util';
import {insideLevelList} from '../../../static/js/config';
import { _debounce } from '@/public/debounce.js';
// 引入签约主体数据
const contractList = require('../../../static/json/contracting-entity.json');
// 引入岗位名称数据
const positionList = require('../../../static/json/position-title.json');
export default {
  name: 'users',
  // 注册组件
  components: {
    orgTree
  },

  // 父组件传值子组件
  props: {
    // 按钮级权限
    btns: {
      type: Object
    }
  },

  // 无白屏刷新方法注入
  inject: ['reload'],

  // 监听
  watch: {
    // 按钮权限数据
    btns (val, oldVal) {
      // 刷新当前页
      this.reload();
    },
    'editForm.compDept' (val, oldVal) {
      if (this.$refs.cascaderDept) {
        this.$refs.cascaderDept.dropDownVisible = false;
      }
    },
    'editForm.location' (val, oldVal) {
      if (this.$refs.cascaderLoc) {
        this.$refs.cascaderLoc.dropDownVisible = false;
      }
    },
    'editForm.insured' (val, oldVal) {
      if (this.$refs.cascader) {
        this.$refs.cascader.dropDownVisible = false;
      }
    }
  },

  // 创建实例后执行
  created () {
    // 按钮级授权
    this.authorization(this.$store.state.btns);

    // 获取所有公司
    this.getComp();

    // 获取所有部门
    this.getDept();

    // 获取所有员工
    this.getUsersAll();

    // 加载分页数据
    this.getUsersDataByPage();

    // 获取所有部门信息
    this.getDeptList();

    // 获取所有地区数据
    this.assembleAreaList();

    // 获取签约主体数据
    this.getContractList();

    // 获取岗位名称数据
    this.getPositionList();
  },

  // 过滤器
  filters: {
    // 时间显示过滤
    filterTime (value) {
      return moment(value).format('YYYY-MM-DD') === 'Invalid date' ? '' : moment(value).format('YYYY-MM-DD');
    },
    // 当前部门级别过滤  val 列值  depts [当前列， 当前员工所在部门级别， 3>2>1]
    fileLv (val, depts) {
      // 一级部门列
      if (depts[0] === 1) {
        // 当前所在部门级别
        if (depts[1] === 1) {
          val = depts[2];
        }
        if (depts[1] === 2) {
          val = depts[3];
        }
        if (depts[1] === 3) {
          val = depts[4];
        }
        return val;
      }
      // 二级部门列
      if (depts[0] === 2) {
        // 当前所在部门级别
        if (depts[1] === 1) {
          val = '无';
        }
        if (depts[1] === 2) {
          val = depts[2];
        }
        if (depts[1] === 3) {
          val = depts[3];
        }
        return val;
      }
      // 三级部门列
      if (depts[0] === 3) {
        // 当前所在部门级别
        if (depts[1] === 1) {
          val = '无';
        }
        if (depts[1] === 2) {
          val = '无';
        }
        if (depts[1] === 3) {
          val = depts[2];
        }
        return val;
      }
    },

    // 过滤身份证null值
    filterIdCard (val) {
      if (val === 'null') {
        val = '';
      }
      return val;
    }
  },

  // 当前页面数据
  data () {
    return {
      // 归属地回显
      baseLocation: [],
      // 参险地回显
      baseInsured: [],
      // 部门回显
      baseDept: [],
      // 签约主体数据
      signCompanyList: [],
      // 岗位名称数据
      positionList: [],
      // 公司部门所有数据
      option: [],
      // 归属地所有数据
      areaOption: [],
      isAll: false,
      timeSliceVisible: false,
      // 随机生成的员工id
      randomUserId: '',

      // 按钮显示隐藏  - 默认值
      btnSel: true,
      btnDel: true,
      btnUpload: true,
      btnDown: true,
      btnAdd: true,
      btnEdit: true,

      // 获取所有公司
      compsList: [],

      // 获取所有用户
      usersAll: [],

      // 检索匹配
      restaurants: [],
      state: '',
      timeout: null,

      // 获取所有部门
      compdepts: [],

      // 获取公司部门选择框子组件选中值
      compDept: [],
      // 用户选择框子组件选中值
      getUser: [],

      // 根据所选公司获取对应部门
      depList: [{value: '', label: '无', children: []}],

      // 修改弹窗 - 公司部门子组件默认选中值
      // selcpmsVal: [],

      // 搜索条件
      formInline: {
        compId: '',
        deptId: '',
        userId: '',
        status: '',
        type: '0',
        signCompany: '0',
        userLevel: '',
        insideLevel: ''
      },
      // 编辑界面输入框校验规则
      editFormRules: {
        userId: [{ required: true, message: '请输入员工工号', trigger: 'blur' }],
        // password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
        userName: [{ required: true, message: '请输入员工姓名', trigger: 'blur' }],
        sex: [{ required: true, message: '请选择员工性别', trigger: 'blur' }],
        status: [{ required: true, message: '请选择工作状态', trigger: 'change' }],
        location: [{ required: true, message: '请输入归属地', trigger: 'blur' }],
        position: [{ required: true, message: '请输入岗位名称', trigger: 'blur' }],
        // wechat: [{ required: true, message: '请输入企业微信账号', trigger: 'blur' }],
        joinTime: [{ required: true, message: '请选择入职时间', trigger: 'blur' }],
        type: [{ required: true, message: '请选择员工类别', trigger: 'blur' }],
        signCompany: [{ required: true, message: '请选择签约主体', trigger: 'blur' }],
        userLevel: [{ required: true, message: '请输入客户级别', trigger: 'blur' }],
        // insideLevel: [{ required: true, message: '请输入内部级别', trigger: 'blur' }],
        compDept: [{ required: true, message: '请选择部门名称', trigger: 'blur' }],
        insured: [{ required: true, message: '请选择社保公积金参险地', trigger: 'blur' }],
        idCard: [{ required: true, message: '请输入身份证号码', trigger: 'blur' }, {validator: (rule, value, callback) => {
          if (value.length < 18) {
            callback(new Error('请输入18位身份证号码'));
          } else {
            callback();
          }
        },
        trigger: 'blur'}],
        birthday: [{ required: true, message: '请选择出生年月', trigger: 'blur' }],
        email: [{ required: true, message: '请输入邮箱', trigger: 'blur' }],
        tell: [{ required: true, message: '请输入联系方式', trigger: 'blur' }, {validator: (rule, value, callback) => {
          if (value.length < 11) {
            callback(new Error('请输入11位联系方式'));
          } else {
            callback();
          }
        },
        trigger: 'blur'}],
        workTime: [{ required: true, message: '请选择参加工作时间', trigger: 'blur' }]
      },
      // 列表数据
      usersData: [{}],
      // 当前页
      currentPage: 1,
      // 当前数
      pageSize: 20,
      // 总条目数
      total: 20,

      // 弹窗类别
      dialogStatus: '',

      // 工号不允许修改
      isedit: true,

      // 弹窗标题
      textMap: {
        edit: '变更信息'
      },
      // 弹窗是否显示
      dialogFormVisible: false,

      // 界面默认数据
      editForm: {
        compDept: [],
        // userId: '',
        password: '', // 密码
        userName: '', // 员工姓名
        sex: '', // 性别
        status: 0, // 在职状态
        location: '', // 归属地
        position: '', // 岗位名称
        wechat: '', // 企业微信账号
        joinTime: '', // 入职时间
        note: '', // 备注说明
        email: '', // 邮箱
        insuredGs: '', // 社保缴纳公司
        tell: '', // 联系方式
        quitTime: '', // 离职时间
        birthday: '', // 出生年月日
        type: '', // 员工类型
        signCompany: '', // 签约主体
        userLevel: '', // 客户级别
        insideLevel: '', // 内部级别
        workTime: '', // 参加工作时间
        caliber: '', // 财务口径
        idCard: '', // 身份证号码
        insured: '', // 社保公积金参险地
        insuredBase: '', // 社保基数
        accumBase: '' // 公积金基数
      },

      // 离职调岗弹出窗

      // 状态
      modalVisible: false,
      // 标题
      changeText: '',
      // 表单
      changeForm: {},

      changeFormRules: {
        day: [{ required: true, message: '请选择生效日期', trigger: 'change' }]
      },
      // 调岗/离职
      isOut: true,
      // 导出变更历史表头
      columns: [
        {title: '员工姓名', key: 'userName'},
        {title: '员工工号', key: 'userId'},
        {title: '变更日期', key: 'date'},
        {title: '原内部级别', key: 'oldInsideLevel'},
        {title: '现内部级别', key: 'insideLevel'},
        {title: '原归属地', key: 'oldLocation'},
        {title: '现归属地', key: 'location'},
        {title: '原客户级别', key: 'oldUserLevel'},
        {title: '现客户级别', key: 'userLevel'},
        {title: '原公积金参险地', key: 'oldInsured'},
        {title: '现公积金参险地', key: 'insured'},
        {title: '原社保基数', key: 'oldInsuredBase'},
        {title: '现社保基数', key: 'insuredBase'},
        {title: '原公积金基数', key: 'oldAccumBase'},
        {title: '现公积金基数', key: 'accumBase'},
        {title: '转出一级部门', key: 'oldDn1'},
        {title: '转出二级部门', key: 'oldDn2'},
        {title: '转出三级部门', key: 'oldDeptName'},
        {title: '转入一级部门', key: 'dn1'},
        {title: '转入二级部门', key: 'dn2'},
        {title: '转入三级部门', key: 'deptName'}
      ]
    };
  },

  mounted () {
    this.restaurants = this.loadAll();
    // this.getHeight();
    // 增加监听事件，窗口变化时得到高度。
    // window.addEventListener('resize', this.getHeight, false);
  },

  methods: {
    // 表格高度自适应
    // getHeight () {
    //   // 获取浏览器高度并计算得到表格所用高度。
    //   this.tableHeight = document.documentElement.clientHeight - 472;
    // },
    // 按钮级授权
    authorization (data) {
      let _this = this;
      for (let i in data) {
        if (data['sel'] === 0) {
          _this.btnSel = false;
        }
        if (data['add'] === 0) {
          _this.btnAdd = false;
        }
        if (data['del'] === 0) {
          _this.btnDel = false;
        }
        if (data['upload'] === 0) {
          _this.btnUpload = false;
        }
        if (data['down'] === 0) {
          _this.btnDown = false;
        }
        if (data['edit'] === 0) {
          _this.btnEdit = false;
        }
        return i;
      }
    },

    // 获取所有公司
    getComp () {
      let _this = this;
      _this.$http.post('api/findAllCompNoPage').then(res => {
        let { code, datas } = res;
        // 判断Code状态
        if (code === 0) {
          for (let i = datas.length; i--;) {
            _this.compsList.push({
              compId: datas[i].compId,
              compName: datas[i].compName
            });
          }
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 获取所有部门
    getDept () {
      let _this = this;
      // 获取部门列表
      _this.$http.post('api/findDeptByCompNoPage').then(res => {
        let { code, datas } = res;
        if (code === 0) {
          _this.compdepts = datas;
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 根据所选公司获取对应部门
    compDeplist () {
      let _this = this;

      let compId = _this.formInline.compId;
      // 重置部门
      _this.formInline.deptId = '';
      _this.depList = [];

      if (compId !== '') {
        let params = {
          compId: compId
        };
        // 获取对应部门ID的部门信息
        _this.$http.post('api/findDeptByCompNoPage', params).then(res => {
          let { code, datas } = res;
          // 判断Code状态
          if (code === 0) {
          // 匹配数据
            for (let i = datas.length; i--;) {
              _this.depList.push({
                deptId: datas[i].deptId,
                deptName: datas[i].deptName
              });
            }
          }
        }).catch(err => {
          if (err === undefined) {
            _this.$message({
              message: '服务器响应异常！',
              type: 'error'
            });
            return false;
          }
        });
      }
    },

    // 获取所有员工数据
    getUsersAll () {
      let _this = this;
      let params = {
        status: ''
      };
      _this.$http.post('api/findAllBaseUsers', params).then(res => {
        let { code, datas } = res;
        if (code === 0) {
          for (let i = datas.length; i--;) {
            _this.usersAll.push({
              compName: datas[i].compName,
              deptName: datas[i].deptName,
              userId: datas[i].userId,
              userName: datas[i].userName
            });
          };
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 加载全部员工数据
    loadAll () {
      return this.usersAll;
    },

    // 自动检索匹配
    querySearchAsync (queryString, cb) {
      let _this = this;
      let restaurants = _this.restaurants;
      let results = queryString ? restaurants.filter(_this.createStateFilter(queryString)) : restaurants;
      clearTimeout(_this.timeout);
      _this.timeout = setTimeout(() => {
        cb(results);
      }, 300 * Math.random());
    },

    // 查询
    createStateFilter (queryString) {
      return (state) => {
        return (state.userName.indexOf(queryString) === 0);
      };
    },

    // 选中赋值
    handleSelect (item) {
      this.formInline.userId = item.userId;
    },

    // 查询
    selHandle: function () {
      let _this = this;
      // 收集请求数据
      let params = {
        userId: _this.formInline.userId,
        deptId: _this.formInline.deptId === null ? '' : _this.formInline.deptId.length ? _this.formInline.deptId[_this.formInline.deptId.length - 1].split('-')[0] : '',
        compId: _this.formInline.compId,
        status: _this.formInline.status,
        type: _this.formInline.type,
        signCompany: _this.formInline.signCompany,
        userLevel: _this.formInline.userLevel,
        insideLevel: _this.formInline.insideLevel,
        pageNum: _this.currentPage,
        pageSize: _this.pageSize
      };
      // 根据员工ID 部门ID 公司ID查询分页数据
      _this.$http.raw('api/findAllUser', params).then(res => {
        let { code, datas } = res;
        // 判断Code状态
        if (code === 0) {
          // 总页数
          _this.total = datas.total;
          // 数据结果集
          _this.usersData = datas.list;
          // 解决删除当前页数据后仍留在那一页 不跳回上一页的bug
          if (!datas.list.length && _this.currentPage !== 1) {
            // 当前页减一
            _this.currentPage -= 1;
            // 调用自己
            _this.getUsersDataByPage();
          }
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 重置搜索
    reseatHandle () {
      let _this = this;
      _this.formInline = {
        userId: '',
        deptId: '',
        compId: '',
        status: '',
        type: '0',
        signCompany: '0',
        userLevel: '',
        insideLevel: ''
      };
      // 收集请求数据
      let params = {
        userId: '',
        deptId: '',
        compId: '',
        status: '',
        type: '0',
        signCompany: '0',
        userLevel: '',
        insideLevel: '',
        pageNum: _this.currentPage,
        pageSize: _this.pageSize
      };
      // 根据员工ID 部门ID 公司ID查询分页数据
      _this.$http.raw('api/findAllUser', params).then(res => {
        let { code, datas } = res;
        // 判断Code状态
        if (code === 0) {
          // 总页数
          _this.total = datas.total;
          // 数据结果集
          _this.usersData = datas.list;
          // 解决删除当前页数据后仍留在那一页 不跳回上一页的bug
          if (!datas.list.length && _this.currentPage !== 1) {
            // 当前页减一
            _this.currentPage -= 1;
            // 调用自己
            _this.getUsersDataByPage();
          }
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },
    // 显示新增界面
    addHandle: function () {
      let _this = this;
      // 允许添加工号
      _this.isedit = false;
      // 弹窗类型
      _this.dialogStatus = 'create';
      // 弹窗显示状态
      _this.dialogFormVisible = true;
      _this.compDept = '';
      // 初始化弹窗表单 公司部门选择框子组件选中数据
      _this.selcpmsVal = [];
      // 初始化新增界面默认数据
      _this.editForm = {
        compDept: '',
        // userId: '',
        password: '',
        userName: '',
        sex: '',
        status: '0',
        location: '',
        position: '',
        wechat: '',
        joinTime: '',
        note: '',
        email: '',
        insuredGs: '',
        tell: '',
        quitTime: '',
        birthday: '',
        type: '', // 员工类型
        signCompany: '', // 签约主体
        userLevel: '', // 客户级别
        insideLevel: '', // 内部级别
        workTime: '', // 参加工作时间
        caliber: '', // 财务口径
        idCard: '', // 身份证号码
        insured: '', // 社保公积金参险地
        insuredBase: '', // 社保基数
        accumBase: '' // 公积金基数
      };
    },
    // 获取公司部门选择框选中值
    // getCompDept (data) {
    //   let _this = this;
    //   if (_this.isOut) {
    //     _this.compDept = data;
    //     _this.changeForm.compDept = data;
    //     // _this.changeForm.location = data[1];
    //   }
    //   _this.editForm.compDept = data;
    //   // _this.editForm.location = data[1];
    // },
    // 切换员工类型显示隐藏员工工号
    changeType (val) {
      let _this = this;
      if (val === '5') {
        _this.isShowUserCode = true;
      } else {
        _this.isShowUserCode = false;
      }
    },
    // 添加
    createData: _debounce(function () {
      let _this = this;
      _this.$nextTick(() => {
        // 判断是否通过验证规则验证
        _this.$refs['editForm'].validate(valid => {
          if (valid) {
            // 收集请求参数
            let params = {
              userName: _this.editForm.userName === null ? '' : _this.editForm.userName,
              userId: _this.editForm.userId ? _this.editForm.userId : '1',
              // 密码Md5转换
              password: _this.$md5('123456'),
              sex: _this.editForm.sex === null ? '' : _this.editForm.sex,
              status: _this.editForm.status === null ? '' : _this.editForm.status,
              type: _this.editForm.type === null ? '' : _this.editForm.type,
              signCompany: _this.editForm.signCompany === null ? '' : _this.editForm.signCompany,
              userLevel: _this.editForm.userLevel === null ? '' : _this.editForm.userLevel,
              insideLevel: _this.editForm.insideLevel === null ? '' : _this.editForm.insideLevel,
              birthday: _this.editForm.birthday === null ? '' : moment(_this.editForm.birthday).format('YYYY-MM-DD'),
              email: _this.editForm.email === null ? '' : _this.editForm.email,
              insuredGs: _this.editForm.insuredGs === null ? '' : _this.editForm.insuredGs,
              wechat: '',
              tell: _this.editForm.tell === null ? '' : _this.editForm.tell,
              location: _this.editForm.location[0] + _this.editForm.location[1],
              position: _this.editForm.position === null ? '' : _this.editForm.position,
              joinTime: _this.editForm.joinTime === null ? '' : moment(_this.editForm.joinTime).format('YYYY-MM-DD'),
              // quitTime: _this.editForm.quitTime === null ? '' : moment(_this.editForm.quitTime).format('YYYY-MM-DD'),
              mark: 1,
              createUserId: _this.$store.state.userinfo.userId,
              createTime: new Date(),
              updateUserId: _this.$store.state.userinfo.userId,
              updateTime: new Date(),
              deptIds: [{
                compId: 'HFXX',
                deptId: _this.editForm.compDept.length ? _this.editForm.compDept[_this.editForm.compDept.length - 1].split('-')[0] : ''
              }],
              note: JSON.stringify([_this.editForm.compDept, _this.editForm.location, _this.editForm.insured]),
              workTime: _this.editForm.workTime === null ? '' : moment(_this.editForm.workTime).format('YYYY-MM-DD'),
              caliber: _this.editForm.caliber === null ? '' : _this.editForm.caliber,
              idCard: _this.editForm.idCard === null ? '' : _this.editForm.idCard,
              insured: _this.editForm.insured[0] + _this.editForm.insured[1],
              insuredBase: _this.editForm.insuredBase === null ? '' : _this.editForm.insuredBase,
              accumBase: _this.editForm.accumBase === null ? '' : _this.editForm.accumBase
            };
            // 获取选择用户工号
            // let getUser = {
            //   userId: _this.editForm.userId
            // };
            // 添加用户
            _this.$http.raw('api/insertUser', params).then(res => {
              let { code } = res;
              // 判断Code状态
              if (code === 0) {
                _this.$message({
                  message: '添加成功！',
                  type: 'success'
                });
                _this.$refs['editForm'].resetFields();
                _this.dialogFormVisible = false;
                // 刷新列表
                _this.getUsersDataByPage();
                // 获取所有员工
                _this.getUsersAll();
              }
            }).catch(err => {
              if (err === undefined) {
                _this.$message({
                  message: '服务器响应异常！',
                  type: 'error'
                });
                return false;
              }
            });
            // 通过用户工号判断是否被占用
            // _this.$http.post('api/checkUserByUserId', getUser).then(res => {
            //   let { code, datas } = res;
            //   // 判断Code状态
            //   if (code === 0) {
            //     if (datas) {
            //       _this.$message({
            //         message: '工号被占用！',
            //         type: 'error'
            //       });
            //     } else {
            //     }
            //   }
            // }).catch(err => {
            //   if (err === undefined) {
            //     _this.$message({
            //       message: '服务器响应异常！',
            //       type: 'error'
            //     });
            //     return false;
            //   }
            // });
          }
        });
      });
    }, 200),
    // 显示编辑界面
    editHandle: function (row, type) {
      let _this = this;
      let compJson = row.note && row.note !== '无' ? JSON.parse(row.note) : [[row.deptId + '-' + row.deptName], [row.location], [row.insured]];
      // console.log(compJson);
      // 修改
      if (type === 1) {
        // 不允许修改工号
        _this.isedit = true;
        // 弹框类型
        _this.dialogStatus = 'edit';
        // 弹框显示状态
        _this.dialogFormVisible = true;

        // 公司部门选择框子组件出事选中值
        // _this.selcpmsVal = [row.compName, row.deptName];

        // 弹框窗表单初始值赋值
        _this.editForm = Object.assign({}, row);

        // 弹出窗表单 - 公司部门选择框子组件初始值赋值
        _this.editForm.compDept = compJson[0];
        // 弹出窗表单 员工性别数据类型转换
        _this.editForm.sex = row.sex.toString();
        // 弹出窗表单 员工在职状态数据类型转换
        _this.editForm.status = row.status.toString();
        // 弹出窗表单 员工在职状态数据类型转换
        _this.editForm.idCard = row.idCard === 'null' ? '' : row.idCard;
        // 弹出窗表单 员工类型数据类型转换
        _this.editForm.type = row.type ? row.type.toString() : '';
        // 弹出窗表单 内部级别数据类型转换
        _this.editForm.insideLevel = row.insideLevel ? row.insideLevel.toString() : '';
        // 弹出窗表单 签约主体数据类型转换
        _this.editForm.signCompany = row.signCompany ? row.signCompany.toString() : '';
        // 弹出窗表单 归属地回显
        _this.editForm.location = compJson[1].length > 1 ? compJson[1] : compJson[1][0];
        // 弹出窗表单 社保公积金参险地回显
        _this.editForm.insured = compJson[2].length > 1 ? compJson[2] : compJson[2][0];

        sessionStorage.setItem('oldUserInfo', JSON.stringify(row));

        // 弹出窗表单初始值赋值
        _this.changeForm = {
          userId: row.userId,
          userName: row.userName,
          day: moment(new Date()).format('YYYY-MM-DD')
        };
      }
      // 调岗
      if (type === 2) {
        _this.changeText = '员工调岗';
        _this.modalVisible = true;
        _this.isOut = true;
        _this.baseLocation = compJson[1];
        _this.baseInsured = compJson[2];
        // 初始值赋值
        // _this.selcpmsVal = [row.compName, row.deptName];

        sessionStorage.setItem('oldUserInfo', JSON.stringify(row));

        // 弹出窗表单初始值赋值
        _this.changeForm = {
          userId: row.userId,
          userName: row.userName,
          compDept: compJson[0],
          day: moment(new Date()).format('YYYY-MM-DD')
        };
      }
      // 离职
      if (type === 3) {
        _this.changeText = '员工离职';
        _this.modalVisible = true;
        _this.isOut = false;
        _this.baseDept = compJson[0];
        _this.baseLocation = compJson[1];
        _this.baseInsured = compJson[2];
        sessionStorage.setItem('oldUserInfo', JSON.stringify(row));

        // 弹出窗表单初始值赋值
        _this.changeForm = {
          userId: row.userId,
          userName: row.userName,
          day: moment(new Date()).format('YYYY-MM-DD')
        };
      }
    },

    // 修改
    editData: _debounce(function () {
      let _this = this;
      let oldrow = JSON.parse(sessionStorage.getItem('oldUserInfo'));
      // console.log(oldrow, 'oldrow');
      // _this.baseLocation = _this.editForm.location;
      // _this.baseInsured = _this.editForm.insured;
      _this.$nextTick(() => {
        // 判断是否通过验证规则验证
        _this.$refs['editForm'].validate(valid => {
          if (valid) {
            let changes = {
              userId: _this.editForm.userId,
              userName: _this.editForm.userName,
              type: 4,
              date: moment(_this.editForm.day).format('YYYY-MM-DD'),
              note: JSON.stringify({
                oldInfo: {
                  userName: oldrow.userName, // 员工姓名
                  userId: oldrow.userId, // 员工工号
                  signCompany: oldrow.signCompany, // 签约主体
                  dn1: oldrow.dn1 === '无' ? (oldrow.dn2 === '无' ? oldrow.deptName : oldrow.dn2) : oldrow.dn1, // 一级部门
                  dn2: oldrow.dn1 === '无' ? (oldrow.dn2 !== '无' ? oldrow.deptName : '无') : oldrow.dn2, // 二级部门
                  deptName: oldrow.dn1 === '无' || oldrow.dn2 === '无' ? '无' : oldrow.deptName, // 三级部门
                  position: oldrow.position, // 岗位名称
                  type: oldrow.type, // 员工类型
                  insideLevel: oldrow.insideLevel, // 内部级别
                  status: oldrow.status, // 员工状态
                  location: oldrow.location, // 归属地
                  joinTime: moment(oldrow.joinTime).format('YYYY-MM-DD'), // 入职时间
                  workTime: oldrow.workTime, // 参加工作时间
                  caliber: oldrow.caliber, // 财务口径
                  userLevel: oldrow.userLevel, // 客户级别
                  idCard: oldrow.idCard, // 身份证号码
                  insured: oldrow.insured, // 社保公积金参险地
                  insuredBase: oldrow.insuredBase, // 社保基数
                  accumBase: oldrow.accumBase, // 公积金基数
                  sex: oldrow.sex, // 性别
                  birthday: oldrow.birthday, // 出生年月日
                  email: oldrow.email, // 邮箱
                  insuredGs: oldrow.insuredGs, // 社保缴纳公司
                  tell: oldrow.tell // 联系方式
                  // quitTime: oldrow.quitTime, // 离职时间
                  // wechat: oldrow.wechat, // 企业微信账号
                  // note: oldrow.note, // 备注说明
                },
                newInfo: {
                  userName: _this.editForm.userName, // 员工姓名
                  userId: oldrow.userId, // 员工工号
                  signCompany: _this.editForm.signCompany, // 签约主体
                  dn1: oldrow.dn1 === '无' ? (oldrow.dn2 === '无' ? oldrow.deptName : oldrow.dn2) : oldrow.dn1, // 一级部门
                  dn2: oldrow.dn1 === '无' ? (oldrow.dn2 !== '无' ? oldrow.deptName : '无') : oldrow.dn2, // 二级部门
                  deptName: oldrow.dn1 === '无' || oldrow.dn2 === '无' ? '无' : oldrow.deptName, // 三级部门
                  position: _this.editForm.position, // 岗位名称
                  type: _this.editForm.type, // 员工类型
                  insideLevel: _this.editForm.insideLevel, // 内部级别
                  status: oldrow.status, // 员工状态
                  location: _this.editForm.location[0] + _this.editForm.location[1], // 归属地
                  joinTime: moment(_this.editForm.joinTime).format('YYYY-MM-DD'), // 入职时间
                  workTime: _this.editForm.workTime, // 参加工作时间
                  caliber: _this.editForm.caliber, // 财务口径
                  userLevel: _this.editForm.userLevel, // 客户级别
                  idCard: _this.editForm.idCard, // 身份证号码
                  insured: _this.editForm.insured[0] + _this.editForm.insured[1], // 社保公积金参险地
                  insuredBase: _this.editForm.insuredBase, // 社保基数
                  accumBase: _this.editForm.accumBase, // 公积金基数
                  sex: _this.editForm.sex, // 性别
                  birthday: _this.editForm.birthday, // 出生年月日
                  email: _this.editForm.email, // 邮箱
                  insuredGs: _this.editForm.insuredGs, // 社保缴纳公司
                  tell: _this.editForm.tell // 联系方式
                  // quitTime: oldrow.quitTime, // 离职时间
                  // wechat: oldrow.wechat, // 企业微信账号
                  // note: oldrow.note, // 备注说明
                }
              })
            };
            _this.$http.raw('api/insertPersonnel', changes).then(res => {
              let { code } = res;
              if (code === 0) {
                // 收集请求数据
                let params = {
                  id: _this.editForm.id,
                  userName: _this.editForm.userName === null ? '' : _this.editForm.userName,
                  userId: _this.editForm.userId ? _this.editForm.userId : '1',
                  // 密码Md5转换
                  password: _this.$md5('123456'),
                  sex: _this.editForm.sex === null ? '' : _this.editForm.sex,
                  status: _this.editForm.status === null ? '' : _this.editForm.status,
                  type: _this.editForm.type === null ? '' : _this.editForm.type,
                  signCompany: _this.editForm.signCompany === null ? '' : _this.editForm.signCompany,
                  userLevel: _this.editForm.userLevel === null ? '' : _this.editForm.userLevel,
                  insideLevel: _this.editForm.insideLevel === null ? '' : _this.editForm.insideLevel,
                  birthday: _this.editForm.birthday === null ? '' : moment(_this.editForm.birthday).format('YYYY-MM-DD'),
                  email: _this.editForm.email === null ? '' : _this.editForm.email,
                  insuredGs: _this.editForm.insuredGs === null ? '' : _this.editForm.insuredGs,
                  wechat: '',
                  tell: _this.editForm.tell === null ? '' : _this.editForm.tell,
                  location: _this.editForm.location[0] + _this.editForm.location[1],
                  position: _this.editForm.position === null ? '' : _this.editForm.position,
                  joinTime: _this.editForm.joinTime === null ? '' : _this.editForm.joinTime,
                  quitTime: _this.editForm.quitTime === null ? '' : _this.editForm.quitTime,
                  mark: 1,
                  createUserId: _this.$store.state.userinfo.userId,
                  createTime: new Date(),
                  updateUserId: _this.$store.state.userinfo.userId,
                  updateTime: new Date(),
                  deptIds: [{
                    compId: 'HFXX',
                    deptId: _this.editForm.compDept.length ? _this.editForm.compDept[_this.editForm.compDept.length - 1].split('-')[0] : ''
                  }],
                  note: JSON.stringify([_this.editForm.compDept, _this.editForm.location, _this.editForm.insured]),
                  workTime: _this.editForm.workTime === null ? '' : moment(_this.editForm.workTime).format('YYYY-MM-DD'),
                  caliber: _this.editForm.caliber === null ? '' : _this.editForm.caliber,
                  idCard: _this.editForm.idCard === null ? '' : _this.editForm.idCard,
                  insured: _this.editForm.insured[0] + _this.editForm.insured[1],
                  insuredBase: _this.editForm.insuredBase === null ? '' : _this.editForm.insuredBase,
                  accumBase: _this.editForm.accumBase === null ? '' : _this.editForm.accumBase
                };
                // 修改用户信息
                _this.$http.raw('api/updateUser', params).then(res => {
                  let { code } = res;
                  // 判断Code状态
                  if (code === 0) {
                    _this.$message({
                      message: '修改成功！',
                      type: 'success'
                    });
                    // 初始化弹出窗表单数据
                    _this.$refs['editForm'].resetFields();
                    // 关闭弹窗
                    _this.dialogFormVisible = false;
                    // 刷新列表
                    _this.getUsersDataByPage();
                    // 获取所有员工
                    _this.getUsersAll();
                  }
                }).catch(err => {
                  if (err === undefined) {
                    _this.$message({
                      message: '服务器响应异常！',
                      type: 'error'
                    });
                    return false;
                  }
                });
              }
            });
          }
        });
      });
    }, 200),

    // 调岗/离职
    changeUser: _debounce(function () {
      let _this = this;
      let oldrow = JSON.parse(sessionStorage.getItem('oldUserInfo'));
      _this.$nextTick(() => {
        // 判断是否通过验证规则验证
        _this.$refs['changeForm'].validate(valid => {
          if (valid) {
            // 调岗
            if (_this.isOut) {
              let index = _this.changeForm.compDept.length - 1;
              let changes = {
                userId: _this.changeForm.userId,
                userName: _this.changeForm.userName,
                type: 1,
                date: _this.changeForm.day,
                note: JSON.stringify(
                  {
                    oldInfo: {
                      userName: oldrow.userName, // 员工姓名
                      userId: oldrow.userId, // 员工工号
                      signCompany: oldrow.signCompany, // 签约主体
                      dn1: oldrow.dn1 === '无' ? (oldrow.dn2 === '无' ? oldrow.deptName : oldrow.dn2) : oldrow.dn1, // 一级部门
                      dn2: oldrow.dn1 === '无' ? (oldrow.dn2 !== '无' ? oldrow.deptName : '无') : oldrow.dn2, // 二级部门
                      deptName: oldrow.dn1 === '无' || oldrow.dn2 === '无' ? '无' : oldrow.deptName, // 三级部门
                      position: oldrow.position, // 岗位名称
                      type: oldrow.type, // 员工类型
                      insideLevel: oldrow.insideLevel, // 内部级别
                      status: oldrow.status, // 员工状态
                      location: oldrow.location, // 归属地
                      joinTime: moment(oldrow.joinTime).format('YYYY-MM-DD'), // 入职时间
                      workTime: oldrow.workTime, // 参加工作时间
                      caliber: oldrow.caliber, // 财务口径
                      userLevel: oldrow.userLevel, // 客户级别
                      idCard: oldrow.idCard, // 身份证号码
                      insured: oldrow.insured, // 社保公积金参险地
                      insuredBase: oldrow.insuredBase, // 社保基数
                      accumBase: oldrow.accumBase, // 公积金基数
                      sex: oldrow.sex, // 性别
                      birthday: oldrow.birthday, // 出生年月日
                      email: oldrow.email, // 邮箱
                      insuredGs: oldrow.insuredGs, // 社保缴纳公司
                      tell: oldrow.tell // 联系方式
                      // quitTime: oldrow.quitTime, // 离职时间
                      // wechat: oldrow.wechat, // 企业微信账号
                      // note: oldrow.note, // 备注说明
                    },
                    newInfo: {
                      userName: oldrow.userName, // 员工姓名
                      userId: oldrow.userId, // 员工工号
                      signCompany: oldrow.signCompany, // 签约主体
                      dn1: index === 2 ? _this.changeForm.compDept[0].split('-')[1] : (index === 1 ? _this.changeForm.compDept[0].split('-')[1] : _this.changeForm.compDept[index].split('-')[1]), // 一级部门
                      dn2: index === 2 ? _this.changeForm.compDept[1].split('-')[1] : (index === 1 ? _this.changeForm.compDept[1].split('-')[1] : '无'), // 一级部门
                      deptName: index === 2 ? _this.changeForm.compDept[index].split('-')[1] : '无', // 三级部门
                      position: oldrow.position, // 岗位名称
                      type: oldrow.type, // 员工类型
                      insideLevel: oldrow.insideLevel, // 内部级别
                      status: oldrow.status, // 员工状态
                      location: oldrow.location, // 归属地
                      joinTime: moment(oldrow.joinTime).format('YYYY-MM-DD'), // 入职时间
                      workTime: oldrow.workTime, // 参加工作时间
                      caliber: oldrow.caliber, // 财务口径
                      userLevel: oldrow.userLevel, // 客户级别
                      idCard: oldrow.idCard, // 身份证号码
                      insured: oldrow.insured, // 社保公积金参险地
                      insuredBase: oldrow.insuredBase, // 社保基数
                      accumBase: oldrow.accumBase, // 公积金基数
                      sex: oldrow.sex, // 性别
                      birthday: oldrow.birthday, // 出生年月日
                      email: oldrow.email, // 邮箱
                      insuredGs: oldrow.insuredGs, // 社保缴纳公司
                      tell: oldrow.tell // 联系方式
                      // quitTime: oldrow.quitTime, // 离职时间
                      // wechat: oldrow.wechat, // 企业微信账号
                      // note: oldrow.note, // 备注说明
                    }
                  }
                )
              };
              _this.$http.raw('api/insertPersonnel', changes).then(res => {
                let {code} = res;
                if (code === 0) {
                  let params = oldrow;
                  // params.location = _this.changeForm.compDept[1];
                  params.compId = 'HFXX';
                  params.compName = '浩方信息';
                  params.deptId = _this.changeForm.compDept[index].split('-')[0];
                  params.deptName = _this.changeForm.compDept[index].split('-')[1];
                  params.note = JSON.stringify([_this.changeForm.compDept, _this.baseLocation, _this.baseInsured]);
                  // params.id = _this.editForm.id;
                  // 修改用户信息
                  _this.$http.raw('api/updateUser', params).then(res => {
                    let { code } = res;
                    // 判断Code状态
                    if (code === 0) {
                      _this.$message({
                        message: '修改成功！',
                        type: 'success'
                      });
                      // 初始化弹出窗表单数据
                      _this.$refs['changeForm'].resetFields();
                      // 关闭弹窗
                      _this.modalVisible = false;
                      // 刷新列表
                      _this.getUsersDataByPage();
                      // 获取所有员工
                      _this.getUsersAll();
                    }
                  }).catch(err => {
                    if (err === undefined) {
                      _this.$message({
                        message: '服务器响应异常！',
                        type: 'error'
                      });
                      return false;
                    }
                  });
                }
              }).catch(err => {
                if (err === undefined) {
                  _this.$message({
                    message: '服务器响应异常！',
                    type: 'error'
                  });
                  return false;
                }
              });
            }
            // 离职
            if (!_this.isOut) {
              let changes = {
                userId: _this.changeForm.userId,
                userName: _this.changeForm.userName,
                type: 2,
                date: moment(_this.changeForm.day).format('YYYY-MM-DD'),
                note: JSON.stringify(
                  {
                    oldInfo: {
                      userName: oldrow.userName, // 员工姓名
                      userId: oldrow.userId, // 员工工号
                      signCompany: oldrow.signCompany, // 签约主体
                      dn1: oldrow.dn1 === '无' ? (oldrow.dn2 === '无' ? oldrow.deptName : oldrow.dn2) : oldrow.dn1, // 一级部门
                      dn2: oldrow.dn1 === '无' ? (oldrow.dn2 !== '无' ? oldrow.deptName : '无') : oldrow.dn2, // 二级部门
                      deptName: oldrow.dn1 === '无' || oldrow.dn2 === '无' ? '无' : oldrow.deptName, // 三级部门
                      position: oldrow.position, // 岗位名称
                      type: oldrow.type, // 员工类型
                      insideLevel: oldrow.insideLevel, // 内部级别
                      status: oldrow.status, // 员工状态
                      location: oldrow.location, // 归属地
                      joinTime: moment(oldrow.joinTime).format('YYYY-MM-DD'), // 入职时间
                      workTime: oldrow.workTime, // 参加工作时间
                      caliber: oldrow.caliber, // 财务口径
                      userLevel: oldrow.userLevel, // 客户级别
                      idCard: oldrow.idCard, // 身份证号码
                      insured: oldrow.insured, // 社保公积金参险地
                      insuredBase: oldrow.insuredBase, // 社保基数
                      accumBase: oldrow.accumBase, // 公积金基数
                      sex: oldrow.sex, // 性别
                      birthday: oldrow.birthday, // 出生年月日
                      email: oldrow.email, // 邮箱
                      insuredGs: oldrow.insuredGs, // 社保缴纳公司
                      tell: oldrow.tell // 联系方式
                      // quitTime: oldrow.quitTime, // 离职时间
                      // wechat: oldrow.wechat, // 企业微信账号
                      // note: oldrow.note, // 备注说明
                    },
                    newInfo: {
                      compName: '',
                      deptName: '',
                      userName: '', // 员工姓名
                      userId: '', // 员工工号
                      sex: '', // 性别
                      location: '', // 归属地
                      position: '', // 岗位名称
                      // wechat: oldrow.wechat, // 企业微信账号
                      joinTime: '', // 入职时间
                      // note: oldrow.note, // 备注说明
                      email: '', // 邮箱
                      insuredGs: '', // 社保缴纳公司
                      tell: '', // 联系方式
                      // quitTime: oldrow.quitTime, // 离职时间
                      birthday: '', // 出生年月日
                      type: '', // 员工类型
                      signCompany: '', // 签约主体
                      userLevel: '', // 客户级别
                      insideLevel: '', // 内部级别
                      workTime: '', // 参加工作时间
                      caliber: '', // 财务口径
                      idCard: '', // 身份证号码
                      insured: '', // 社保公积金参险地
                      insuredBase: '', // 社保基数
                      accumBase: '', // 公积金基数
                      status: '1' // 员工状态
                    }
                  }
                )
              };

              _this.$http.raw('api/insertPersonnel', changes).then(res => {
                let { code } = res;

                if (code === 0) {
                  let params = oldrow;
                  params.status = 1;
                  params.quitTime = moment(_this.changeForm.day).format('YYYY-MM-DD');
                  params.note = JSON.stringify([_this.baseDept, _this.baseLocation, _this.baseInsured]);
                  // 修改用户信息
                  _this.$http.raw('api/updateUser', params).then(res => {
                    let { code } = res;
                    // 判断Code状态
                    if (code === 0) {
                      let userAsset = {
                        userId: _this.changeForm.userId
                      };

                      _this.$http.post('api/updateAssetStatus', userAsset).then(res => {
                        let {code, datas} = res;
                        if (code === 0) {
                          if (datas[0].assetCode !== null) {
                            for (let i = datas.length; i--;) {
                              setTimeout(() => {
                                let nstat = datas[i].assetStatus;
                                if (nstat === 1) {
                                  nstat = '占用';
                                }
                                if (nstat === 2) {
                                  nstat = '空闲';
                                }
                                if (nstat === 3) {
                                  nstat = '维修';
                                }
                                if (nstat === 4) {
                                  nstat = '报废';
                                }
                                if (nstat === 5) {
                                  nstat = '停用';
                                }
                                let changes = {
                                  assetCode: datas[i].assetCode,
                                  operation: '离职变更',
                                  note: '归属人' + _this.changeForm.userName + ' [' + _this.changeForm.userId + ']已离职，状态原始值：' + nstat + ' 变更后：空闲'
                                };
                                _this.$http.raw('api/insertAssetRecord', changes).then().catch(err => {
                                  if (err === undefined) {
                                    _this.$message({
                                      message: '服务器响应异常！',
                                      type: 'error'
                                    });
                                    return false;
                                  }
                                });
                              }, 200);
                            }

                            _this.$message({
                              message: '修改成功！',
                              type: 'success'
                            });
                            // 初始化弹出窗表单数据
                            _this.$refs['changeForm'].resetFields();
                            // 关闭弹窗
                            _this.modalVisible = false;
                            // 刷新列表
                            _this.getUsersDataByPage();
                            // 获取所有员工
                            _this.getUsersAll();
                          } else {
                            _this.$message({
                              message: '修改成功！',
                              type: 'success'
                            });
                            // 初始化弹出窗表单数据
                            _this.$refs['changeForm'].resetFields();
                            // 关闭弹窗
                            _this.modalVisible = false;
                            // 刷新列表
                            _this.getUsersDataByPage();
                            // 获取所有员工
                            _this.getUsersAll();
                          }
                        }
                      }).catch(err => {
                        if (err === undefined) {
                          _this.$message({
                            message: '服务器响应异常！',
                            type: 'error'
                          });
                          return false;
                        }
                      });

                      // _this.$message({
                      //   message: '修改成功！',
                      //   type: 'success'
                      // });
                      // // 初始化弹出窗表单数据
                      // _this.$refs['changeForm'].resetFields();
                      // // 关闭弹窗
                      // _this.modalVisible = false;
                      // // 刷新列表
                      // _this.getUsersDataByPage();
                      // // 获取所有员工
                      // _this.getUsersAll();
                    }
                  }).catch(err => {
                    if (err === undefined) {
                      _this.$message({
                        message: '服务器响应异常！',
                        type: 'error'
                      });
                      return false;
                    }
                  });
                }
              }).catch(err => {
                if (err === undefined) {
                  _this.$message({
                    message: '服务器响应异常！',
                    type: 'error'
                  });
                  return false;
                }
              });
            }
          }
        });
      });
    }, 200),

    // 刷新页面数据
    getUsersDataByPage () {
      let _this = this;
      // 收集请求参数
      let params = {
        userId: _this.formInline.userId === null ? '' : _this.formInline.userId,
        deptId: _this.formInline.deptId === null ? '' : _this.formInline.deptId.length ? _this.formInline.deptId[_this.formInline.deptId.length - 1].split('-')[0] : '',
        compId: _this.formInline.compId === null ? '' : _this.formInline.compId,
        status: _this.formInline.status === null ? '0' : _this.formInline.status,
        type: _this.formInline.type === null ? '0' : _this.formInline.type,
        signCompany: _this.formInline.signCompany === null ? '0' : _this.formInline.signCompany,
        userLevel: _this.formInline.userLevel === null ? '' : _this.formInline.userLevel,
        insideLevel: _this.formInline.insideLevel === null ? '' : _this.formInline.insideLevel,
        pageNum: _this.currentPage,
        pageSize: _this.pageSize
      };

      // 获取分页数据
      _this.$http.raw('api/findAllUser', params).then(res => {
        let { code, datas } = res;
        if (code === 0) {
          // 总页数
          _this.total = datas.total;
          // 数据结果集
          _this.usersData = datas.list;
          // 解决删除当前页数据后仍留在那一页 不跳回上一页的bug
          if (!datas.list.length && _this.currentPage !== 1) {
            // 当前页减一
            _this.currentPage -= 1;
            // 调用自己
            _this.getUsersDataByPage();
          }
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 每页显示的条数改变
    handleSizeChange (val) {
      this.pageSize = val;
      // 调用刷新页面
      this.getUsersDataByPage();
    },
    // 当前页码
    handleCurrentChange (val) {
      this.currentPage = val;
      // 调用
      this.getUsersDataByPage();
    },

    // 获取对应部门ID的部门信息
    getDeptList () {
      let _this = this;
      let params = {
        compId: 'HFXX'
      };
      _this.$http.post('api/findDeptByCompNoPage', params).then(res => {
        let { code, datas } = res;
        if (code === 0) {
          let options = [];
          let secondOpt = [];
          let thirdOpt = [];
          datas.map(item => {
            if (item.level === 1) {
              options.push({
                value: item.deptId + '-' + item.deptName,
                label: item.deptName,
                id: item.deptId,
                children: []
              });
            };
            if (item.level === 2) {
              secondOpt.push({
                value: item.deptId + '-' + item.deptName,
                label: item.deptName,
                parentId: item.parentId,
                id: item.deptId,
                children: []
              });
            }
            if (item.level === 3) {
              thirdOpt.push({
                value: item.deptId + '-' + item.deptName,
                label: item.deptName,
                parentId: item.parentId
              });
            }
          });
          thirdOpt.forEach((item, index) => {
            secondOpt.forEach((ite, idx) => {
              if (item.parentId === ite.id) {
                ite.children.push(item);
              }
            });
          });
          secondOpt.forEach((item, index) => {
            options.forEach((ite, idx) => {
              if (item.parentId === ite.id) {
                ite.children.push(item);
              }
            });
          });
          _this.option = options;
          _this.depList = _this.depList.concat(options);
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 组装地区数据
    assembleAreaList () {
      let _this = this;
      let provinceOpt = [];
      let cityOpt = [];
      province.map(item => {
        provinceOpt.push({
          value: item.name,
          label: item.name,
          parentId: item.parentId,
          id: item.code,
          children: []
        });
      });
      city.map(item => {
        cityOpt.push({
          value: item.name,
          label: item.name,
          parentId: item.parentId
        });
      });
      cityOpt.forEach((item, index) => {
        provinceOpt.forEach((ite, idx) => {
          if (item.parentId === ite.id) {
            ite.children.push(item);
          }
        });
      });
      _this.areaOption = provinceOpt;
    },

    // 获取签约主体数据
    getContractList () {
      let _this = this;
      _this.signCompanyList = contractList.data;
    },

    // 获取岗位名称数据
    getPositionList () {
      let _this = this;
      _this.positionList = positionList.data;
    },

    // 调岗切换部门
    handleChangeDept (val) {
      let _this = this;
      _this.changDept = val;
    },
    // 导出设置弹框打开
    getHistory () {
      let _this = this;
      _this.timeSliceVisible = true;
      _this.exportTitle = '变更历史导出';
    },

    // 导出设置数据收集
    setUpAssetExcel () {
      let _this = this;
      let params = {
        beginTime: _this.formInline.logTime && _this.formInline.logTime.length > 0 ? moment(_this.formInline.logTime[0]).format('YYYY-MM-DD') : '',
        endTime: _this.formInline.logTime && _this.formInline.logTime.length > 0 ? moment(_this.formInline.logTime[1]).format('YYYY-MM-DD') : ''
      };
      _this.$http.raw('api/findPersonHists', params).then(res => {
        let {code, datas} = res;
        if (code === 0) {
          let histryData = [];
          datas.map(item => {
            let chaNote = item.note;
            let oldNote = chaNote.indexOf('oldInfo') > -1 ? JSON.parse(chaNote) : {oldInfo: {dn1: chaNote.substring(11, 5)}, newInfo: {dn1: chaNote}};
            let oldInfo = oldNote.oldInfo;
            let newInfo = oldNote.newInfo;
            item.oldInsideLevel = oldInfo.insideLevel ? getName(insideLevelList, oldInfo.insideLevel) : '';
            item.insideLevel = newInfo.insideLevel ? getName(insideLevelList, newInfo.insideLevel) : '';
            item.oldLocation = oldInfo.location ? oldInfo.location : '';
            item.location = newInfo.location ? newInfo.location : '';
            item.oldUserLevel = oldInfo.userLevel ? oldInfo.userLevel : '';
            item.userLevel = newInfo.userLevel ? newInfo.userLevel : '';
            item.oldInsured = oldInfo.insured ? oldInfo.insured : '';
            item.insured = newInfo.insured ? newInfo.insured : '';
            item.oldInsuredBase = oldInfo.insuredBase ? oldInfo.insuredBase : '';
            item.insuredBase = newInfo.insuredBase ? newInfo.insuredBase : '';
            item.oldAccumBase = oldInfo.accumBase ? oldInfo.accumBase : '';
            item.accumBase = newInfo.accumBase ? newInfo.accumBase : '';
            item.oldDn1 = oldInfo.dn1 ? oldInfo.dn1 : '';
            item.oldDn2 = oldInfo.dn2 ? oldInfo.dn2 : '';
            item.oldDeptName = oldInfo.deptName ? oldInfo.deptName : '';
            item.dn1 = newInfo.dn1 ? newInfo.dn1 : '';
            item.dn2 = newInfo.dn2 ? newInfo.dn2 : '';
            item.deptName = newInfo.deptName ? newInfo.deptName : '';
            item.date = moment(item.date).format('YYYY-MM-DD');
            histryData.push(item);
          });
          _this.formInline.logTime = [];
          _this.timeSliceVisible = false;
          export2Excel('员工信息变更历史', _this.columns, histryData);
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    }
  }
};
</script>

<style lang='scss' scoped>
@import './index.scss';
</style>
<style lang="scss">
  .userlevel-box {
    .el-form-item__label {
      line-height: 20px;
    }
  }
</style>
